package com.ysstech.finance.controller;


import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.ysstech.common.annotation.YssLog;
import com.ysstech.common.annotation.YssPermissions;
import com.ysstech.common.controller.BaseController;
import com.ysstech.common.exception.BusinessException;
import com.ysstech.common.util.resultutil.RestResult;
import com.ysstech.common.util.resultutil.ResultGenerator;
import com.ysstech.finance.entity.SubjectProject;
import com.ysstech.finance.service.SubjectProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 财务科目科目核算方案
 * </p>
 *
 * @author lishuangliang
 * @since 2021-04-07
 */
@Controller
@Slf4j
@Api(tags = "科目核算方案管理api")
@RequestMapping("/subjectProject")
public class SubjectProjectController extends BaseController {

    @Autowired
    private SubjectProjectService subjectProjectService;

    @YssPermissions(value = {"finance:subject:project"})
    @ApiOperation(value = "跳转科目核算方案管理页面")
    @YssLog(module = "科目核算方案管理", remark = "跳转科目核算方案管理页面")
    @RequestMapping(value = "/page")
    public String page() throws Exception {
        return "finance/subjectProject";
    }


    /**
     * 获取科目核算方案信息
     *
     * @return
     */
    @YssPermissions(value = {"finance:subject:project"})
    @ApiOperation(value = "获取科目核算方案管信息")
    @YssLog(module = "科目核算方案管管理", remark = "获取科目核算方案管信息")
    @PostMapping(value = "/listInfo")
    @ResponseBody
    public RestResult listInfo(SubjectProject subjectProject, String page, String rows) throws Exception {
        return ResultGenerator.getSuccessResult("获取科目核算方案管信息成功",
                subjectProjectService.queryAllSubjectProject(subjectProject, this.getPage(page, rows)));
    }

    /**
     * 新增科目核算方案的方法
     *
     * @param subjectProject
     * @return
     */
    @YssPermissions(value = {"finance:subject:project:add"})
    @ApiOperation(value = "新增科目核算方案信息")
    @YssLog(module = "科目核算方案管管理", remark = "新增科目核算方案信息")
    @RequestMapping(value = "/addSubjectProject")
    @ResponseBody
    public RestResult addSubjectProject(SubjectProject subjectProject) throws Exception {
        subjectProjectService.addSubjectProject(subjectProject);
        return ResultGenerator.getSuccessResult("新增科目核算方案信息成功！");
    }

    /**
     * 修改科目核算方案信息
     *
     * @return
     */
    @YssPermissions(value = {"finance:subject:project:edit"})
    @ApiOperation(value = "修改科目核算方案信息")
    @YssLog(module = "科目核算方案管管理", remark = "修改科目核算方案信息")
    @RequestMapping(value = "/editSubjectProject")
    @ResponseBody
    public RestResult editSubjectProject(SubjectProject subjectProject) throws Exception {
        if (subjectProject == null || StringUtils.isBlank(subjectProject.getId())) {
            throw new BusinessException("获取科目核算方案信息失败，请稍后重试！");
        }
        subjectProjectService.updateById(subjectProject);
        return ResultGenerator.getSuccessResult("修改科目核算方案信息成功！");
    }

    /**
     * 删除科目核算方案信息
     *
     * @return
     */
    @YssPermissions(value = {"finance:subject:project:del"})
    @ApiOperation(value = "删除科目核算方案信息")
    @YssLog(module = "科目核算方案管管理", remark = "删除科目核算方案信息")
    @RequestMapping(value = "/delSubjectProject")
    @ResponseBody
    public RestResult delSubjectProject(String ids) throws Exception {
        if (StringUtils.isBlank(ids)) {
            throw new BusinessException("获取删除科目核算方案信息失败，请稍后重试！");
        }
        List<String> list = JSONArray.parseArray(ids, String.class);
        subjectProjectService.delSubjectProject(list);
        return ResultGenerator.getSuccessResult("删除科目核算方案信息成功！");
    }

}
